package com.hk.patterntrains.oberverpattern.withinner;


import com.hk.patterntrains.oberverpattern.typeone.DisplayElement;

import java.util.Observable;
import java.util.Observer;

public class CurrentConditionDisplay implements Observer ,DisplayElement {

    private float temp;
    private float humidity;
    private float pressure;

    private Observable observable;

    public CurrentConditionDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof  WeatherData){
            WeatherData weatherData = (WeatherData) o;
            temp = weatherData.getTemp();
            humidity = weatherData.getHumidity();
            pressure = weatherData.getPressure();
            if(arg!=null){
                System.out.println("arg="+arg);
            }
            display();
        }


    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "CurrentConditionDisplay{" +
                "temp=" + temp +
                ", humidity=" + humidity +
                ", pressure=" + pressure +
                '}';
    }
}
